#!/bin/bash

# This file is part of libmarco
# http://code.google.com/p/libmarco/

# Wrapper for screen.
# Starts a given application inside screen, unless it's already running.
# Uses screen -x option to allow multiple terminals to share the session
# (i.e. i.e. through ssh).

sessionname="myapp"; #Session ID
procname="/bin/myapp.exe"; #Application 
run_dir="$HOME/myapp_folder/" #App running directory

cd $run_dir;
screen -x -S $sessionname;
if [[ "$?" == "0" ]]; then
	echo "Leaving resumed session"
	
else
	echo "Session not found, press enter to start it"
	read	
	screen -S $sessionname $procname
fi

if [[ `ps | grep $procname | grep -v grep` ]]; then
	echo "Is $procname running?  YES"
else
	echo "Is $procname running?  NO"
fi
